package com.smart.gui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

import com.jgoodies.forms.factories.FormFactory;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.RowSpec;

public class SMART_T_Main_Application_Window extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel contentPane;

	/**
	 * singleton pattern -- getInstance
	 */
	private static SMART_T_Main_Application_Window uniqueInstanceForm;

	public static synchronized SMART_T_Main_Application_Window getInstance() {
		if (uniqueInstanceForm == null) {
			try {
				uniqueInstanceForm = new SMART_T_Main_Application_Window();
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return uniqueInstanceForm;
	}

	/**
	 * Create the frame.
	 */
	public SMART_T_Main_Application_Window() {
		ButtonHandler handler = new ButtonHandler(this);

		setBackground(Color.WHITE);

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});

		setTitle("SMART-T Main Application Window");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(25, 25, 567, 1019);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		JTextPane txtrWelcomeToSmartt = new JTextPane();
		txtrWelcomeToSmartt.setName("txtrWelcomeToSmartt");
		txtrWelcomeToSmartt.setBackground(Color.WHITE);
		txtrWelcomeToSmartt.setEditable(false);
		txtrWelcomeToSmartt
				.setText("Welcome. This application will walk you through the 3 stages of the SMART-T framework (shown below in flow chart form).\r\n\r\nInstructions:\r\n1) Use the Questionnaire buttons -- \"Business Drivers\", \"Technical Factors\", and \"Operational Results\"-- to navigate/view all the available questions for each stage.\r\n2) Type answers to the relevant questions presented in all questionnaires.\r\n3) Press the \"Analyze Results\" button to have this application determine based on your answers if SMART-T recommends you to migrate, not migrate or do more analysis for migrating testing to the cloud. \r\n4) Press the \"Save\" button to have all your input and recommendations saved to disk\r\n5) Press the \"Exit\" button to shutdown this application\r\n6) Press the \"About\" button to see the information about who developed this application.");
		contentPane.add(txtrWelcomeToSmartt, BorderLayout.NORTH);

		JLabel lblNewLabel = new JLabel("SMART-T Flowchart");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD | Font.ITALIC, 14));
		lblNewLabel.setVerticalTextPosition(SwingConstants.TOP);
		lblNewLabel.setHorizontalTextPosition(SwingConstants.CENTER);
		lblNewLabel.setBackground(Color.WHITE);
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setFocusable(false);
		lblNewLabel.setIcon(new ImageIcon(SMART_T_Questionnaire_Form.class
				.getResource("/com/smart/gui/SMART-T_Flow_Chart_473x532.JPG")));
		contentPane.add(lblNewLabel, BorderLayout.CENTER);

		JPanel panel = new JPanel();
		panel.setBackground(Color.WHITE);
		contentPane.add(panel, BorderLayout.SOUTH);
		panel.setLayout(new FormLayout(new ColumnSpec[] {
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.MIN_COLSPEC,
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.MIN_COLSPEC,
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.MIN_COLSPEC,
				FormFactory.LABEL_COMPONENT_GAP_COLSPEC,
				FormFactory.MIN_COLSPEC, }, new RowSpec[] {
				FormFactory.LINE_GAP_ROWSPEC, FormFactory.MIN_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC, FormFactory.MIN_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
				FormFactory.RELATED_GAP_ROWSPEC, }));

		JLabel lblQuestionnaires = new JLabel("Questionnaires:");
		panel.add(lblQuestionnaires, "2, 2, left, center");

		JButton button = new JButton("Business Drivers");
		button.setActionCommand(ButtonHandler.BD);
		button.addActionListener(handler);
		panel.add(button, "4, 2, fill, top");

		JLabel lblCompleted = new JLabel("Completed?");
		panel.add(lblCompleted, "2, 4");

		JCheckBox bdcheckBox = new JCheckBox();
		bdcheckBox.setName("bd");
		bdcheckBox.setBackground(Color.WHITE);
		bdcheckBox.setEnabled(false);
		panel.add(bdcheckBox, "4, 4");

		JCheckBox tdcheckBox = new JCheckBox();
		tdcheckBox.setName("td");
		tdcheckBox.setBackground(Color.WHITE);
		tdcheckBox.setEnabled(false);
		panel.add(tdcheckBox, "6, 4");

		JCheckBox orcheckBox = new JCheckBox();
		orcheckBox.setName("or");
		orcheckBox.setBackground(Color.WHITE);
		orcheckBox.setEnabled(false);
		panel.add(orcheckBox, "8, 4");

		JButton button_1 = new JButton("Technical Factors");
		button_1.setActionCommand(ButtonHandler.TF);
		button_1.addActionListener(handler);
		panel.add(button_1, "6, 2, fill, top");

		JButton button_2 = new JButton("Operational Results");
		button_2.setActionCommand(ButtonHandler.OR);
		button_2.addActionListener(handler);
		panel.add(button_2, "8, 2, fill, top");

		JLabel lblActions = new JLabel("Actions:");
		panel.add(lblActions, "2, 6");

		JButton btnAnalyzeResults = new JButton("Analyze Results");
		btnAnalyzeResults.setActionCommand(ButtonHandler.AR);
		btnAnalyzeResults.addActionListener(handler);
		panel.add(btnAnalyzeResults, "6, 6, fill, default");

		JButton btnSave = new JButton("Save");
		btnSave.setActionCommand(ButtonHandler.SAVE);
		btnSave.addActionListener(handler);
		panel.add(btnSave, "4, 6, fill, default");

		JButton btnAbout = new JButton("About");
		btnAbout.setActionCommand(ButtonHandler.ABOUT);
		btnAbout.addActionListener(handler);
		panel.add(btnAbout, "8, 6");
	}
}
